<?php
class TreeNode {
    public $val = null;
    public $left = null;
    public $right = null;
    function __construct($value) {
        $this->val = $value;
    }
}

class Solution {

    /**
     * @param TreeNode $root
     * @return Integer
     */
    function maxDepth($root) {
        if ($root == null) {
            return 0;
        }
        if ($root->left == null && $root->right == null) {
            return 1;
        }
        return max($this->maxDepth($root->left),$this->maxDepth($root->right)) + 1;
    }
}